﻿using System;
using System.Configuration;
using System.Data.SqlClient;
using System.Transactions;

namespace EasyGo.Data
{
    public static class Helper
    {
        public static void ExecTransatcion(Action ac)
        {
            using (var scope = new TransactionScope())
            {
                ac();
                scope.Complete();
            }
        }
        public static SqlConnection OpenConnction()
        {
            var connection = new SqlConnection(ConfigurationManager.ConnectionStrings["Data"].ConnectionString);
            connection.Open();
            return connection;
        }

        public static SqlCommand CreateProcedure(this SqlConnection conn, string name)
        {
            SqlCommand cmd = conn.CreateCommand();
            cmd.CommandText = name;
            cmd.CommandType = System.Data.CommandType.StoredProcedure;
            return cmd;
        }
    }
}
